package com.dongrj.framework.starter.log.config;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.TtlMDCAdapter;
import org.slf4j.spi.MDCAdapter;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author dongrongjun
 * @date 2020/08/04
 * 初始化TtlMDCAdapter实例，并替换MDC中的adapter对象
 */
@Slf4j
public class TtlMDCAdapterInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        log.info("--------------logback start--------------");
        MDCAdapter instance = TtlMDCAdapter.getInstance();
        instance.put("traceId", "start");
    }
}
